class Mqtt {
  //   "mqtt": {
  //     "host": "tcp://47.108.186.244:1883",
  //     "client_id": "05TNJtuQMUaGx3VjqievNQaXomOrPtN5",
  //     "username": "15215004902",
  //     "password": "nFQFoz5Qe7q9XOKvMwfjJn8s7jiIzRjg",
  //     "subscribe": "/sc/driver/subscribe/01gnUnZwptZ1tFGc",
  //     "publish": "/sc/driver/publish/yzmnWnQH5EtjmQPJ"
  // }

  final String host;
  final String client_id;
  final String username;
  final String password;
  final String subscribe;
  final String publish;

  Mqtt(
    this.host,
    this.client_id,
    this.username,
    this.password,
    this.subscribe,
    this.publish,
  );

  factory Mqtt.fromMap(Map<String, dynamic> json) => Mqtt(
      json['host'],
      json['client_id'],
      json['username'],
      json['password'],
      json['subscribe'],
      json['publish']);
}

class Menu {
  //  "id": 3,
  //           "pid": 0,
  //           "name": "name",
  //           "url": "url",
  //           "icon": "icon",
  //           "status": 1,
  final int id;
  final int pid;
  final String name;
  final String url;
  final String icon;
  final int status;
  final List<Menu>? menu;

  Menu(
    this.id,
    this.pid,
    this.name,
    this.url,
    this.icon,
    this.status, {
    this.menu,
  });


  factory Menu.fromMap(Map<String, dynamic> json) {
    dynamic menuTemp = json["menu"];
    if (menuTemp != null) {
      return Menu(
        json['id'],
        json['pid'],
        json['name'],
        json['url'],
        json['icon'],
        json['status'],
        menu: List<Menu>.from(menuTemp.map((x) => Menu.fromMap(x))),
      );
    } else {
      return Menu(
        json['id'],
        json['pid'],
        json['name'],
        json['url'],
        json['icon'],
        json['status'],
      );
    }
  }
}

class UserModel {
  //  "id": 4,
  //       "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNCIsIm1vYmlsZSI6IjE1MjE1MDA0OTAyIiwibWFya2V0X2lkIjoiMjQiLCJjcF9pZCI6IjQiLCJleHAiOjE2NDgwMzc0OTUsImlzcyI6ImRyaXZlciJ9.KEJubvwIy7rZjWPGBJBD3FTqZICG68tNHUV7XfAo8kw",
  //       "token_exp": 1648037495,
  //       "mobile": "15215004902",
  //       "role_name": "安全员",
  //       "name": "安全员",
  //       "avatar": "",
  final int id;
  final String token;
  final int token_exp;
  late String mobile;
  late String role_name;
  late String name;
  late String avatar;
  final List<Menu> menu;
  final Mqtt? mqtt;

  UserModel(
    this.id,
    this.token,
    this.token_exp,
    this.mobile,
    this.role_name,
    this.name,
    this.avatar,
    this.menu,
    this.mqtt,
  );

  factory UserModel.fromMap(Map<String, dynamic> json) => UserModel(
      json["id"],
      json["token"],
      json["token_exp"],
      json["mobile"],
      json["role_name"],
      json["name"],
      json["avatar"],
      List<Menu>.from(json["menu"].map((x) => Menu.fromMap(x))),
      Mqtt.fromMap(json["mqtt"]));
}
